package com.loyalove.demo.spark

import java.util.Properties

import org.apache.spark.sql.SparkSession

object SparkSql extends App {
  val spark = SparkSession
    .builder()
    .appName("scala")
    .master("local[*]")
    .getOrCreate()

  val url = "jdbc:mysql://rm-wz96lod4quo919vsp2o.mysql.rds.aliyuncs.com:3306/wateriot"
  val properties = new Properties
  properties.setProperty("driver", "com.mysql.jdbc.Driver")
  properties.setProperty("user", "water")
  properties.setProperty("password", "Water@2018")
  properties.setProperty("useSSL", "false")

  val frame = spark.read.jdbc(url, "meter_data_history", properties)

  println(frame.count())
}
